package q10.GUI;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SpringLayout;

import q10.ArboriFunctionali;


public class GUITemplate  extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static JTextField jtFunctie;
	public static JTextField jtValX;
	public static JTextField jtDerivata;

	public GUITemplate() {
			
        
		Action ea = new ExitAction("Exit", null, this);
        Action sa = new SubmitAction("Parsare", null, this);
        Action sa2 = new SubmitAction("Derivata", null, this);
        Action sa1 = new SubmitAction("Undo",null,this);
        Action sa3 = new SubmitAction("Val.deriv.", null, this);
        
        // Meniu si bara de meniu
        JMenuBar jbr = new JMenuBar();
        JMenu dropmenu= new JMenu("File");
        JMenu dropmenu1 = new JMenu("Edit");
        JMenuItem submitmenu = new JMenuItem(sa);
        JMenuItem exitmenu = new JMenuItem(ea);
        JMenuItem undomenu = new JMenuItem(sa1);
        JMenuItem derivmenu = new JMenuItem(sa2);
        JMenuItem valderivmenu = new JMenuItem(sa3);
        dropmenu.add(submitmenu);
        dropmenu.add(derivmenu);
        dropmenu.add(valderivmenu);
        dropmenu.add(exitmenu);
        dropmenu1.add(undomenu);
        jbr.add(dropmenu);
        jbr.add(dropmenu1);
        setJMenuBar(jbr);
        
        final JPopupMenu pop = new JPopupMenu("PopMenu");
        pop.add(sa);
        pop.add(ea);
        addMouseListener(new MouseAdapter() {
           public void mousePressed(MouseEvent e) {
               showPopup(e);
           }
                  
           public void mouseReleased(MouseEvent e) {
               showPopup(e);
           }
                  
            private void showPopup(MouseEvent e) {
                if (e.isPopupTrigger()) {
                     pop.show(e.getComponent(),
                               e.getX(), e.getY());
                }
            }
         
        });     
       
        
       
       //Panel-ul de jos ce contine 2 butoane
        JPanel jp = new JPanel();        
        JButton subbtn = new JButton(sa);
        
        JButton derivBtn = new JButton(sa2);
        JButton valDerivBtn = new JButton(sa3);
        JButton exitbtn = new JButton(ea);
        
        
        jp.add(subbtn);
        jp.add(derivBtn);
        jp.add(valDerivBtn);
        jp.add(exitbtn);
        
                 
      //Panel-ul de sus ce contine un Label si un Textbox
        JPanel jpS = new JPanel();
        //functia
        
        JLabel jlFunctie = new JLabel("Introduceti functia: ");
        jtFunctie = new JTextField(20);
    
        jpS.add(jlFunctie);
        jpS.add(jtFunctie);
        
        //valoarea lui x 
        JPanel jpM = new JPanel();
        JLabel jlValX = new JLabel("Introduceti valoarea lui x: ");
        jtValX = new JTextField(20);
        
        //derivata
        JLabel jlDerivata = new JLabel("Derivata: ");
        jtDerivata = new JTextField(10);        
        
        
        JLabel jlRezultat = new JLabel("Rezultat: ");
        JLabel jlValoare = new JLabel(" ");
        SpringLayout layout = new SpringLayout();
                
        jpM.setLayout(layout);
        
        jpM.add(jlValX);
        jpM.add(jtValX);
        
        jpM.add(jlRezultat);
        jpM.add(jlValoare);
       // jpM.add(jlDerivata);
       // jpM.add(jtDerivata);
        
        //fixez asezarea etichetei "Introduceti ..." fata de Panel 
        layout.putConstraint(SpringLayout.NORTH, jlValX,5, SpringLayout.NORTH, jpM);
        layout.putConstraint(SpringLayout.WEST, jlValX,5, SpringLayout.WEST, jpM);
        
        //fixez asezare TextField fata de eticheta
        layout.putConstraint(SpringLayout.WEST, jtValX, 5, SpringLayout.EAST, jlValX);
        
        //fixez asezarea etichetei Rezultat fata de eticheta Introduceti ...
        layout.putConstraint(SpringLayout.NORTH, jlRezultat, 15, SpringLayout.SOUTH, jlValX);
        layout.putConstraint(SpringLayout.WEST, jlValoare, 5, SpringLayout.EAST, jlRezultat);
        
        //derivata
        //fixez asezarea etichetei Derivata fata de eticheta Rezultat ...
       // layout.putConstraint(SpringLayout.SOUTH, jlDerivata, 10, SpringLayout.NORTH, jpM);
        //layout.putConstraint(SpringLayout.WEST, jlRezultat, 5, SpringLayout.EAST, jlDerivata);
      //fixez asezare TextField fata de eticheta
        //layout.putConstraint(SpringLayout.EAST, jtDerivata,5, SpringLayout.WEST, jlDerivata);
        
       //Container - ce contine cele 2 Panal-uri definite
        Container con = getContentPane();
        
        con.add(jpS,"North");
        con.add(jpM);
        con.add(jp, "South");
 
        setTitle("Command pattern example");
        setSize(400,200);
        setVisible(true);
        
        
   }


}
